﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LambdaDemo.ConsoleApp.Models;
using System.Data.SqlClient;
using LambdaDemo.ConsoleApp.DBUtility;
using System.Data;

namespace LambdaDemo.ConsoleApp.DataAccess
{
    public class DataDictionaryDB
    {
        /// <summary>
        /// 获取指定类别的公用字典
        /// </summary>
        /// <param name="vConditionEntity">搜索条件</param>
        /// <returns></returns>
        public static Dictionary<int, ShareCodeEntity> GetShareCodeByClassID(int vClassID)
        {
            Dictionary<int, ShareCodeEntity> codeDictionary = new Dictionary<int, ShareCodeEntity>();
            SqlDataReader dr = null;
            try
            {
                SqlParameter[] cmdParams = new SqlParameter[]
                    {
                        SQLHelper.MakeParam("@ClassID",SqlDbType.SmallInt,0,vClassID)
                    };

                dr = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure, "ShareCode_GetShareCodeByClassID", cmdParams);
                while (dr.Read())
                {
                    ShareCodeEntity entity = new ShareCodeEntity();
                    entity.ClassID = vClassID;
                    entity.CodeID = Convert.ToInt32(dr["CodeID"]);
                    entity.CodeNameCN = dr["CodeNameCN"].ToString();
                    entity.CodeNameEN = dr["CodeNameEN"].ToString();
                    entity.IDPath = dr["IDPath"].ToString();
                    entity.NameCnPath = dr["NameCnPath"].ToString();
                    entity.ParentID = Convert.ToInt32(dr["ParentID"]);

                    codeDictionary.Add(entity.CodeID, entity);
                }
            }
            catch (Exception e)
            {
                Exception ex = new Exception("DataDictionaryDB-->GetShareCodeByClassID-->" + e.ToString());
            }
            finally
            {
                if (dr != null)
                    dr.Close();
            }

            return codeDictionary;
        }
    }
}
